package com.donfu.web.controller.house;

import java.util.Date;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.donfu.common.annotation.Log;
import com.donfu.common.core.controller.BaseController;
import com.donfu.common.core.domain.AjaxResult;
import com.donfu.common.enums.BusinessType;
import com.donfu.system.domain.house.HouseUser;
import com.donfu.system.service.house.IHouseUserService;
import com.donfu.common.utils.poi.ExcelUtil;
import com.donfu.common.core.page.TableDataInfo;

/**
 * 用户信息Controller
 * 
 * @author donfu
 * @date 2021-12-01
 */
@RestController
@RequestMapping("/house/user")
public class HouseUserController extends BaseController
{
    @Autowired
    private IHouseUserService houseUserService;

    /**
     * 查询用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('house:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(HouseUser houseUser)
    {
        startPage();
        List<HouseUser> list = houseUserService.selectHouseUserList(houseUser);
        return getDataTable(list);
    }

    /**
     * 导出用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('house:user:export')")
    @Log(title = "用户信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HouseUser houseUser)
    {
        List<HouseUser> list = houseUserService.selectHouseUserList(houseUser);
        ExcelUtil<HouseUser> util = new ExcelUtil<HouseUser>(HouseUser.class);
        return util.exportExcel(list, "用户信息数据");
    }

    /**
     * 获取用户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('house:user:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(houseUserService.selectHouseUserById(id));
    }

    /**
     * 新增用户信息
     */
    @PreAuthorize("@ss.hasPermi('house:user:add')")
    @Log(title = "用户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseUser houseUser)
    {
        return toAjax(houseUserService.insertHouseUser(houseUser));
    }

    /**
     * 修改用户信息
     */
    @PreAuthorize("@ss.hasPermi('house:user:edit')")
    @Log(title = "用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseUser houseUser)
    {
        houseUser.setUpdateDate(new Date());
        return toAjax(houseUserService.updateHouseUser(houseUser));
    }

    /**
     * 删除用户信息
     */
    @PreAuthorize("@ss.hasPermi('house:user:remove')")
    @Log(title = "用户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(houseUserService.deleteHouseUserByIds(ids));
    }
}
